package com.blankii.androidlibrary.base

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.FileUtils
import com.google.android.material.snackbar.Snackbar

/**
 * author: blankii
 * created on: 2024/4/16 17:23
 * description:activity 的父类
 */
abstract class BaseBindingActivity<VB : ViewBinding>(
    private val inflate: (LayoutInflater) -> VB, private val setContentView: Boolean = true
) : AppCompatActivity() {
    open val TAG: String
        get() = this::class.simpleName!!

    lateinit var binding: VB

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = inflate(layoutInflater)
        if (setContentView) {
            setContentView(binding.root)
        }
        onInitView()
        onInitData()
        lifecycle.addObserver(LifecycleObserver("${this::class.simpleName!!}"))
    }


    abstract fun onInitView()

    abstract fun onInitData()

    protected fun showSnackBar(text: String) {
        Snackbar.make(this, binding.root, text, 1200).show()
    }
}